#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@desc: .

@Project：kuberCloudTest 
@File：mirror.py
@Author：admin
@Date：2024/4/16 19:17 
"""
from kuberCloudTest.common.basic import basicUtils
from kuberCloudTest.common.constant import OFFSET, LIMIT, AsyncType
from kuberCloudTest.common.utils import _getOperationType
from kuberCloudTest.networks.urls import networkUrls


class vpcRouterMirrorUtils(basicUtils):

    def __init__(self, accessToken):
        super().__init__(accessToken)


def get_utils(accessToken):
    return vpcRouterMirrorUtils(accessToken=accessToken)


def getVpcRouterMirror(accessToken, serviceType: int = 0, **kwargs):
    """
    查询VPC路由器规格信息
    :param accessToken:
    :param serviceType: vpc路由镜像类型
                            0：所有
                            1：私有云
                            2：vCenter
    :param kwargs: limit:
                   offset:
                   keyword: xxx
    :return:
    """
    return get_utils(accessToken).cloud_http_request.get(networkUrls.getVpcRouterMirror.value,
                                                         {
                                                             'offset': kwargs.get('offset', OFFSET),
                                                             'limit': kwargs.get('limit', LIMIT),
                                                             'keyword': kwargs.get('keyword', ''),
                                                             'status': serviceType,
                                                         })


def getVpcRouterMirrorServer(accessToken, serviceType: int = 1, **kwargs):
    """
    查询VPC路由器镜像服务器信息
    :param accessToken:
    :param serviceType: 服务类型
                        1：私有云
                        2：vCenter
    :param kwargs: limit:
                   offset:
                   keyword: xxx
    :return:
    """
    return get_utils(accessToken).cloud_http_request.get(networkUrls.getVpcRouterMirrorServer.value,
                                                         {
                                                             'offset': kwargs.get('offset', OFFSET),
                                                             'limit': kwargs.get('limit', LIMIT),
                                                             'keyword': kwargs.get('keyword', ''),
                                                             'sertype': serviceType,
                                                         })


def saveVpcRouterMirror(accessToken, vpcRouterMirrorName,
                        mirrorServerId, architecture, mFormat, md5Value, serviceType: int = 1, remark=''):
    """
    保存VPC路由器镜像
    :param accessToken:
    :param vpcRouterMirrorName: VPC路由器镜像名称
    :param mirrorServerId: 镜像服务器ID
    :param architecture: CPU架构
    :param mFormat: 镜像格式
    :param md5Value: 镜像MD5值
    :param serviceType: 服务类型
                        1：私有云
                        2：vCenter
    :param remark: 备注
    :return:
    """
    operationType = 5551
    data = _getOperationType(operationType, AsyncType.ASYNC.value)

    data['mname'] = vpcRouterMirrorName
    data['servicetype'] = serviceType
    data['remark'] = remark
    data['msid'] = mirrorServerId
    data['md5value'] = md5Value
    data['architecture'] = architecture
    data['mformat'] = mFormat

    return get_utils(accessToken).cloud_http_request.post(networkUrls.saveVpcRouterMirror.value, data)


def addVpcRouterMirror(accessToken, vpcRouterMirrorId, filePath):
    """
    添加VPC路由器镜像
    :param accessToken:
    :param vpcRouterMirrorId: VPC路由器镜像UUID
    :param filePath: 上传到服务器的镜像文件路径
    :return:
    """
    operationType = 5551
    data = _getOperationType(operationType, AsyncType.SYNC.value)
    data['mirrorId'] = vpcRouterMirrorId
    data['uploadFilePath'] = filePath

    return get_utils(accessToken).cloud_http_request.post(networkUrls.createVpcRouterMirror.value, data)


def exportVpcRouterMirror(accessToken, vpcRouterMirrorIds):
    """
    导出VPC路由器镜像
    :param accessToken:
    :param vpcRouterMirrorIds: VPC路由器镜像UUID(多个使用英文逗号分割)
    :return:
    """
    operationType = 5552
    data = _getOperationType(operationType, AsyncType.ASYNC.value)
    data['ids'] = vpcRouterMirrorIds

    return get_utils(accessToken).cloud_http_request.post(networkUrls.exportVpcRouterMirror.value, data)


def stopVpcRouterMirror(accessToken, vpcRouterMirrorIds):
    """
    停用VPC路由器镜像
    :param accessToken:
    :param vpcRouterMirrorIds: VPC路由器镜像UUID(多个使用英文逗号分割)
    :return:
    """
    operationType = 5553
    data = _getOperationType(operationType, AsyncType.SYNC.value)
    data['ids'] = vpcRouterMirrorIds

    return get_utils(accessToken).cloud_http_request.post(networkUrls.stopVpcRouterMirror.value, data)


def startVpcRouterMirror(accessToken, vpcRouterMirrorIds):
    """
    启用VPC路由器镜像
    :param accessToken:
    :param vpcRouterMirrorIds: VPC路由器镜像UUID(多个使用英文逗号分割)
    :return:
    """
    operationType = 5552
    data = _getOperationType(operationType, AsyncType.SYNC.value)
    data['ids'] = vpcRouterMirrorIds

    return get_utils(accessToken).cloud_http_request.post(networkUrls.startVpcRouterMirror.value, data)


def deleteVpcRouterMirror(accessToken, vpcRouterMirrorIds):
    """
    删除VPC路由器镜像
    :param accessToken:
    :param vpcRouterMirrorIds: VPC路由器镜像UUID(多个使用英文逗号分割)
    :return:
    """
    operationType = 5557
    data = _getOperationType(operationType, AsyncType.SYNC.value)
    data['ids'] = vpcRouterMirrorIds

    return get_utils(accessToken).cloud_http_request.post(networkUrls.deleteVpcRouterMirror.value, data)
